package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.Footprint;
import com.mall.db.service.FootprintService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/footprint/ft")
public class FootprintController extends BaseController<Footprint>{
    @Resource(name="footprintService")
    private FootprintService fps;


    @Override
    public Map<String, Object> find(Footprint footprint) {
        //实现分页
        PageHelper.startPage(footprint.getPage(),footprint.getLimit());

        QueryWrapper<Footprint> qw = new QueryWrapper<>();
        if (!StringUtils.isEmpty(footprint.getUserId())){
            qw.eq("user_id",footprint.getUserId());
        }if (!StringUtils.isEmpty(footprint.getPId())){
            qw.eq("p_id",footprint.getPId());
        }
        List<Footprint> list = fps.list(qw);

        PageInfo<Footprint> page = new PageInfo<>(list,footprint.getLimit());

        return this.findMap(page.getList(), page.getTotal());
    }

}
